package com.pei.controller;

import com.pei.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @RequestMapping("/main")
    public String toMainPage(){
        return "main";
    }

    @RequestMapping("/tologin")
    public String toLoginPage(){
        return "login";
    }

    @RequestMapping("/orderinfo")
    public String orderinfo(){
        return "orderinfo";
    }

    @RequestMapping("/login")
    public String login(User user, Model model, HttpSession session){
        String userName = user.getUsername();
        String password = user.getPassword();
        if(userName!=null&&userName.equals("admin")&&password !=null &&password.equals("123456")){
            session.setAttribute("USER_SESSION",user);
            return "main";
        }
        model.addAttribute("msg","用户名或密码错误");
        return "login";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:tologin";
    }
}
